package com.yeban.javase.day18.test.test1;

import com.yeban.javase.day17.test.test4.MyRunnable;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/11/2
 *
 * 需求：
 * 线程1要执行打印：A和C，线程2要执行打印：B，
 * 但线程1在打印A后，要线程2打印B之后才能打印C，
 * 所以：线程1在打印A后，必须等待线程2打印完B之后才能继续执行。
 *
 * 多线程的情况下 C -> B -> A
 * sleep()、join()、CountDownLatch类、CyclicBarrier类、阻塞队列LinkedBlockingQueue等等
 *
 */
public class SleepCBA {

    public static void main(String[] args) {

        new Thread(() -> {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName());
        }, "线程A").start();

        new Thread(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName());
        }, "线程B").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName());
        }, "线程C").start();

    }
}

